﻿@model IList<FCDB.Entity.FormsRelation>
<div id="divFormsRelation">
     @if (string.IsNullOrEmpty(Request["ViewDetail"]))
        {
         <p style="display:block; height: 28px;">
   <button type="button"  onclick="AddFormsRelation()"  id="btnAddFormsRelation"   class="fj btn_c3 btn_s">关联表单</button>
   <button type="button" onclick="DelFormsRelation()" id="btnDelFormsRelation"  class="fj btn_c3 btn_s">删除</button>

         </p>
         }
    else if(Request["ViewDetail"]=="2")
    {
     
         <p style="display:block;  height: 28px;">
          <button type="button"  onclick="AddFormsRelation()"    class="fj btn_c3 btn_s"    >关联表单</button>
          <button type="button" onclick="DelFormsRelation()"  class="fj btn_c3 btn_s"disabled="disabled" >删除</button>
             </p>
    }else
    {
        <p class="yj_tit" >关联列表</p>
    }
      
    </div>
<div class="con_yj1">
   <table id="tbFormsRelation" class="tbFormsRelation">
       @foreach (var item in Model)
       {
           <tr>
               <td>
                   <input  disabled="disabled"  class="ckFormTitle" name="ckFormTitle" type="checkbox" value="@item.ID"  AppInstanceFormTitle="@item.AppInstanceFormTitle"
                       ProcessGUID="@item.RelationProcessGUID" AppInstanceID="@item.RelationAppInstanceID"  />
               </td>
               <td>
                  <p><a href="@Url.Action("ViewProccessInstance", "MyProcessInstance", new { AppInstanceID = item.RelationAppInstanceID, AppName = item.AppInstanceFormTitle, ProcessGUID = item.ProcessGUID })" target="_blank">@item.AppInstanceFormTitle</a></p>
               </td>
           </tr>
            
       } 
   </table>
</div>

<script type="text/javascript" src=@Url.Content("~/Scripts/lhgdialog.min.js")> </script>
<script type="text/ecmascript">
    function DelFormsRelation() {
        var str = ""; 
        $(".ckFormTitle:checked").each(function () {
            var val = $(this).val();
            if (val != "" && val != "0") {
                str = str + val + ",";
            }
            $(this).parent().parent().remove(); 
        });
        if (str != "") {
            var url = '@Url.Action("DeleteFormsRelateion","Form")'; 
            $.post(url, { rpList: str }, function (data) {
            });
        }
    }
    function FormRelationCallBack(arr) {
        $.each(arr, function (i, item) {
            var url = '@Url.Action("ViewProccessInstance", "MyProcessInstance")' + '?AppInstanceID=' + item.AppInstanceID + '&&AppName=' + item.AppName + '&&ProcessGUID=' + item.ProcessGUID;
            var str = '';
            str += '<tr><td>';
            str += '  <input  class="ckFormTitle" ' + '" ProcessGUID="' + item.ProcessGUID + '" AppInstanceID="' + item.AppInstanceID + '" AppInstanceFormTitle="' + item.AppName + '"  name="ckFormTitle" type="checkbox" value="' + item.ID + '" />';
            str += '</td><td>';
            str += '<p>　<a href="'+url+'" target="_blank">' + item.AppName + '</a> </p>';
            str += '</td></tr>';
            $(str).appendTo("#tbFormsRelation");
        });
    } 
    function AddFormsRelation() {
        var AppInstanceID = $("#hAppInstanceID").val();
        var ProcessGuid = $("#hProcessGuid").val();
        var FormID = $("#hID").val();
        var ActivityGuid = $("#hActivityGuid").val();
        var FormTable = '@ViewContext.RouteData.Values["action"]'
        var url = '@Url.Action("DialogFormsRelationSelect","Form")' + '?AppInstanceID=' + AppInstanceID + '&ProcessGuid=' + ProcessGuid + "&FormID=" + FormID + "&FormTable=" + FormTable + "&ActivityGuid="+ActivityGuid; 
        window.winObj = window;
        window.refresh = FormRelationCallBack;
        window.oDG = $.dialog({
            lock: true,
            background: '#FFF',
            opacity: 0.5,
            id: 'esDialog',
            title: "选择表单",
            titleAlign: 'left',
            content: "url:" + url,
            width: 800,
            height: 650,
            btnBar: false,
            lockScroll: true
        });
    }

</script>